package cn.bugstack.domain.strategy.repository;

import cn.bugstack.domain.strategy.model.entity.StrategyAwardEntity;
import cn.bugstack.domain.strategy.model.entity.StrategyEntity;
import cn.bugstack.domain.strategy.model.entity.StrategyRuleEntity;
import cn.bugstack.domain.strategy.model.vo.RuleTreeVo;
import cn.bugstack.domain.strategy.model.vo.RuleWeightVO;
import cn.bugstack.domain.strategy.model.vo.StrategyAwardRuleModelVo;
import cn.bugstack.domain.strategy.model.vo.StrategyAwardStockKeyVo;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 19872
 * 策略的仓储接口
 */
public interface IStrategyRepository {
    List<StrategyAwardEntity> queryStrategyAwardList(Long strategyId);

    void storeStrategyAwardSearchRateMap(String key, int rateRange, HashMap<Integer, Integer> shuffleStrategyAwardSearchRateMap);

    int getRateRange(Long strategyId);
    int getRateRange(String key);

    Integer getStrategyAwardAssemble(Long strategyId, int rateKey);
    Integer getStrategyAwardAssemble(String key, int rateKey);

    StrategyEntity queryStrategyEntityByStrategyId(Long strategyId);

    StrategyRuleEntity queryStrategyRuleEntity(Long strategyId, String ruleWeight);

    String queryStrategyRuleValue(Long strategyId, Integer awardId, String ruleModel);
    String queryStrategyRuleValue(Long strategyId,  String ruleModel);

    StrategyEntity getStrategyEntityByStrategyId(Long strategyId);

    StrategyAwardRuleModelVo queryStrategyAwardRuleValue(Long strategyId, Integer awardId);

    RuleTreeVo queryRuleTreeVoByTreeId(String treeLock);

    /**
     * 缓存奖品库存
     *
     * @param cacheKey key
     * @param awardCount 库存值
     */
    void cacheStrategyAwardCount(String cacheKey, Integer awardCount);
    /**
     * 缓存扣减库存
     *
     * @param cacheKey key
     */
    Boolean subtractionAwardStock(String cacheKey, Date endDateTime);
    /**
     * 扣减库存延迟消费
     * @param strategyAwardStockKeyVo 策略奖品库存Key标识值对象
     * */
    void awardStockConsumeSendQueue(StrategyAwardStockKeyVo strategyAwardStockKeyVo);

    /**
     * 获取扣减库存的延迟队列
     * @return 策略奖品库存Key标识值对象
     */
    StrategyAwardStockKeyVo takeQueueValue();

    /**
     * 更新奖品库存的库表数据
     * @param strategyId 策略ID
     * @param awardId 奖品ID
     */
    void updateStrategyAwardStock(Long strategyId, Integer awardId);

    /**
     * 查询奖品实体
     * @param strategyId 策略ID
     * @param awardId 奖品ID
     * @return 奖品实体
     */
    StrategyAwardEntity queryStrategyAwardEntity(Long strategyId, Integer awardId);

    /**
     * 根据活动ID查询策略ID
     * @param activityId 活动ID
     * @return 策略ID
     */
    Long queryStrategyIdByActivityId(Long activityId);

    /**
     * 根据活动ID查询抽奖策略奖品列表
     * @param activityId 活动ID
     * @return 策略奖品列表
     */
    List<StrategyAwardEntity> queryRaffleStrategyAwardListByActivityId(Long activityId);

    /**
     * 根据规则树ID查询奖品加锁配置
     * @param treeIds 规则树ID
     * @return 结果
     */
    Map<String, Integer> queryAwardRuleLockCount(String[] treeIds);

    /**
     * 查询用户抽奖次数
     * @param userId 用户ID
     * @param strategyId 策略ID
     * @return 用户抽奖次数
     */
    Integer queryTodayUserRaffleCount(String userId, Long strategyId);

    /**
     * 通过活动ID查询奖品的规则权重
     * @param activityId 活动ID
     * @return 规则权重值对象
     */
    List<RuleWeightVO> queryAwardRuleWeightByActivityId(Long activityId);

    /**
     * 查询用户当前总抽奖次数
     * @param userId 用户ID
     * @param strategyId 策略ID
     * @return 用户当前总抽奖次数
     */
    Integer queryActivityAccountTotalUseCount(String userId, Long strategyId);
}
